<?php

namespace app\common\controller;
use app\common\model\RuinuoControl;
use app\common\model\RuinuoDatabase;
use app\common\model\RuinuoApp;
use app\common\model\RuinuoMode;
use app\common\model\AdminRole;
use app\common\model\AdminOptions;
use app\common\model\RuinuoVerify;
use app\common\model\AdminMenu as ModeAdminMenu;
use app\common\model\AdminDepartment;
use app\common\model\AdminUser;

class Options
{

    public function AdminMenu()
    {

        $list = ModeAdminMenu::field('id,title,parent_id')->orderRaw('sort asc,id desc')->select()->toArray();
        $data['rows'] = GetTree($list, 'parent_id', 'children');
        return BackCode($data);
    }


    public function AdminRole()
    {
        $list = AdminRole::field('id,name')->orderRaw('id desc')->select()->toArray();
        $data['rows'] = $list;
        return BackCode($data);
    }

    public function DataBaseList()
    {
        $list = RuinuoDatabase::field('id,name,comment')->orderRaw('id desc')->select()->toArray();
        $data['rows'] = $list;
        return BackCode($data);
    }

    public function AppList()
    {
        $list = RuinuoApp::field('id,name,num')->orderRaw('id desc')->select()->toArray();
        $data['rows'] = $list;
        return BackCode($data);
    }

    public function ModeList()
    {
        $list = RuinuoApp::field('id,name,num')->orderRaw('id desc')->select()->toArray();
        foreach ($list as $k => $v) {
            $children = RuinuoMode::where("app_id='" . $v['id'] . "'")->field('id,name,num')->orderRaw('id desc')->select()->toArray();
            $list[$k]['children'] = $children;
            if (empty($children)) {
                unset($list[$k]);
            }
        }
        $data['rows'] = array_values($list);
        return BackCode($data);
    }

    public function ButtonNode()
    {
        $list = [
            ['label' => '按钮及节点', 'value' => 1],
            ['label' => '仅节点', 'value' => 2],
            ['label' => '仅按钮', 'value' => 3],
        ];
        $data['rows'] = $list;
        return BackCode($data);
    }

    public function ButtonPosition()
    {
        $list = [
            ['label' => '表格外', 'value' => 1],
            ['label' => '表格内', 'value' => 2],
        ];
        $data['rows'] = $list;
        return BackCode($data);
    }

    public function ButtonType()
    {
        $list = [
            ['label' => '弹窗', 'value' => 'window'],
            ['label' => '新窗口', 'value' => 'open'],
            ['label' => 'ajax请求', 'value' => 'ajax'],
            ['label' => 'js事件', 'value' => 'js'],
            ['label' => '跳转URL', 'value' => 'url'],
        ];
        $data['rows'] = $list;
        return BackCode($data);
    }


    public function ListsStyle()
    {
        $data['rows'] = [
            ['label' => '普通表格', 'value' => 1],
            ['label' => '多行表格', 'value' => 2],
            ['label' => '树形表格', 'value' => 3],
            ['label' => '卡片表格', 'value' => 4],
            ['label' => '图文表格', 'value' => 5],
        ];
        return BackCode($data);
    }


    public function BtnTheme()
    {
        $data['rows'] = [
            ['label' => '普通色', 'value' => 'btn_theme_0'],
            ['label' => '主题色', 'value' => 'btn_theme_1'],
            ['label' => '红色', 'value' => 'btn_theme_2'],
            ['label' => '蓝色', 'value' => 'btn_theme_3'],
            ['label' => '橙色', 'value' => 'btn_theme_4'],
            ['label' => '紫色', 'value' => 'btn_theme_5'],
        ];
        return BackCode($data);
    }

    public function LeftType()
    {
        $data['rows'] = [
            ['label' => '数据源', 'value' => 1],
            ['label' => '应用模块', 'value' => 2],
        ];
        return BackCode($data);
    }


    public function VerifyList()
    {
        $data['rows'] = RuinuoVerify::field("num as value,name as label")->orderRaw('id desc')->select()->toArray();
        return BackCode($data);
    }

    public function OptionsList()
    {
        $data['rows'] = AdminOptions::field("num as value,name as label")->orderRaw('id desc')->select()->toArray();
        return BackCode($data);
    }

    public function Updatetype()
    {
        $RuinuoControl = new RuinuoControl();
        $data['rows'] = $RuinuoControl->where("is_cat=2 and is_table=1")->field("name as label,num as value")->orderRaw('sort asc,id desc')->select()->toArray();
        return BackCode($data);
    }


    public function LeftLists()
    {
        $num = input("num");
        $data = GetOptions($num);
        return BackCode($data);
    }


    public function FormPower()
    {
        $data['rows'] = [
            ['label' => '可编辑', 'value' =>'edit'],
            ['label' => '可新增', 'value' =>'add'],
            ['label' => '可查看', 'value' =>'detail'],
        ];
        return BackCode($data);
    }

    public function DepartmentType()
    {
        $data['rows'] = [
            ['label' => '公司', 'value' =>1],
            ['label' => '部门', 'value' =>2],
            ['label' => '岗位', 'value' =>3],
        ];
        return BackCode($data);
    }

    public function DepartmentList()
    {

        $list = AdminDepartment::where("type!=3")->field('id,name,parent_id')->orderRaw('sort asc,id desc')->select()->toArray();
        $data['rows'] = GetTree($list, 'parent_id', 'children');
        return BackCode($data);
    }

    public function AdminUserList()
    {
        $data['rows'] = AdminUser::field("name,id")->select()->toArray();
        return BackCode($data);
    }

    public function FlowStatus()
    {
        $data = [
            'rows' => [
                ['label' => '未发起', 'value' => 1],
                ['label' => '处理中', 'value' => 2],
                ['label' => '已完成', 'value' => 3],
                ['label' => '已驳回', 'value' => 4],
                ['label' => '已作废', 'value' => 5],
                ['label' => '已取回', 'value' => 6],
            ]
        ];
        return BackCode($data);
    }


}